<?php

require_once 'authpage.php';

/**
 * Description of ProfileController
 *
 * @author user
 */
class ProfileController extends AuthpageController {

    public function index() {
        URL::redirect('photo');
    }

    public function edit($user_id) {
        if ($this->auth_user->user->id != $user_id && $this->auth_user->user->role != 'admin') {
            URL::redirect('profile');
        }

        if (isset($_POST['submit'])) {
            $user = new ORM('user');
            $user->find($user_id);
            $user->set($_POST);
            $user->password = md5($user->password);
            $user->save();
            $this->auth_user->user = $user;
        }

        URL::redirect("profile?uid=$user_id");
    }

}

?>
